/* OSM layers for gvSIG. 
 * Geographic Information System of the Valencian Government
*
* Copyright (C) 2012 Nacho Brodin
* 
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* 
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
* MA  02110-1301, USA.
* 
*/
package org.gvsig.raster.osm.cachestruct;


/**
 * Description of a tile matrix
 * @author Nacho Brodin (nachobrodin@gmail.com)
 */
public class TileMatrix {
    private double                      scaleXDenominator    = 0;
    private double                      scaleYDenominator    = 0;
    private double[]                    topLeftCorner       = null;
    private int                         tileWidth           = 0;
    private int                         tileHeight          = 0;
    private long                        matrixWidth         = 0;
    private long                        matrixHeight        = 0;
    private static final double         MTS_X_GRADO         = 111319.490793274;
    
	public double getScaleXDenominator() {
		return scaleXDenominator;
	}

	public void setScaleXDenominator(double scaleXDenominator) {
		this.scaleXDenominator = scaleXDenominator;
	}
	
	public double getScaleYDenominator() {
		return scaleYDenominator;
	}

	public void setScaleYDenominator(double scaleYDenominator) {
		this.scaleYDenominator = scaleYDenominator;
	}

	public int getTileWidth() {
		return tileWidth;
	}

	public void setTileWidth(int tileWidth) {
		this.tileWidth = tileWidth;
	}

	public int getTileHeight() {
		return tileHeight;
	}

	public void setTileHeight(int tileHeight) {
		this.tileHeight = tileHeight;
	}

	public long getMatrixWidth() {
		return matrixWidth;
	}

	public void setMatrixWidth(long matrixWidth) {
		this.matrixWidth = matrixWidth;
	}

	public long getMatrixHeight() {
		return matrixHeight;
	}

	public void setMatrixHeight(long matrixHeight) {
		this.matrixHeight = matrixHeight;
	}

	public double[] getTopLeftCorner() {
		return topLeftCorner;
	}
	
	public void setTopLeftCorner(double[] topLeftCorner) {
		this.topLeftCorner = topLeftCorner;
	}
    
    /**
     * Gets the width in meters of a tile
     * @param projected
     * @return
     */
    public double getWidthMtsTile(boolean projected) {
    	if(!projected) {
    		return (scaleXDenominator * tileWidth * 0.28) / (MTS_X_GRADO * 1000);
    	} else {
    		return (scaleXDenominator * tileWidth * 0.28) / 1000;
    	}
    }
    
    /**
     * Gets the height in meters of a tile
     * @param projected
     * @return
     */
    public double getHeightMtsTile(boolean projected) {
    	if(!projected) {
    		return (scaleYDenominator * tileHeight * 0.28) / (MTS_X_GRADO * 1000);
    	} else {
    		return (scaleYDenominator * tileHeight * 0.28) / 1000;
    	}
    }
    
	public void print() {
		System.out.println("   *****TileMatrix******");
		System.out.println("   scaleXDenominator:" + getScaleXDenominator());
		System.out.println("   scaleYDenominator:" + getScaleYDenominator());
		if(topLeftCorner != null)
			System.out.println("   topLeftCorner:" + topLeftCorner[0] + ", " + topLeftCorner[1]);
		System.out.println("   tileWidth:" + getTileWidth());
		System.out.println("   tileHeight:" + getTileHeight());
		System.out.println("   matrixWidth:" + getMatrixWidth());
		System.out.println("   matrixHeight:" + getMatrixHeight());
	}
}
